package edu.ucsur.tp.dao;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisDAOFactory extends DAOFactory {

  private SqlSessionFactory sqlSessionFactory = null;
  
  public MyBatisDAOFactory() {
    try {
      String resource = "META-INF/mybatis-config.xml";
      InputStream inputStream = Resources.getResourceAsStream(resource);
      sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  
  @Override
  public UsuarioDAO getUsuario() {
    return new MyBatisUsuarioDAO(sqlSessionFactory);
  }

}
